Add Reset-PSResourceRepository cmdlet to recover from corrupted repository store #1895
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements a new
Reset-PSResourceRepository
cmdlet that allows users to reset the repository store (PSRepositories.xml) to its default state with only PSGallery registered. This addresses the issue where users have no way to recover when the repository store becomes corrupted.Fixes #1839
Problem
When the PSResourceRepository.xml file becomes corrupted (e.g., through manual editing, file system errors, or incomplete writes), PSResourceGet cmdlets fail with XML parsing errors. Users were left with no built-in recovery mechanism and had to manually locate and delete the file, which is not user-friendly.
Solution
This PR introduces:
1. New
Reset-PSResourceRepository
CmdletA new cmdlet that safely resets the repository store to its default configuration:
Key Features:
ConfirmImpact=High
to ensure users understand this is a significant action2. Safe Reset Implementation
The
RepositorySettings.Reset()
method implements a safety-first approach as requested:This ensures that if anything goes wrong during the reset process, the original file is preserved and restored.
3. Improved Error Messages
Updated the error message in
CheckRepositoryStore()
to guide users:Before:
After:
Testing
Added comprehensive test coverage with 6 test cases:
Breaking Changes
None. This is a new cmdlet that doesn't modify any existing functionality.
Example Usage
Related Issues
Addresses the concerns raised in issue comments:
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
1k9vsblobprodcus379.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)37cvsblobprodcus359.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)4myvsblobprodcus32.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)51yvsblobprodcus36.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)5dkvsblobprodcus355.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)7devsblobprodcus323.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)7k6vsblobprodcus337.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)7tjvsblobprodcus341.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)bcnvsblobprodcus378.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)c50vsblobprodcus330.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)c78vsblobprodcus322.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)dlbvsblobprodcus316.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)fdpvsblobprodcus345.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)gbsvsblobprodcus365.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)kh4vsblobprodcus325.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)kmuvsblobprodcus389.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)l49vsblobprodcus358.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)m6xvsblobprodcus342.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)pkvvsblobprodcus321.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)s4uvsblobprodcus326.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)tphvsblobprodcus375.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)uy6vsblobprodcus34.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)yttvsblobprodcus357.vsblob.vsassets.io
/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.